﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.views.popups {
    import reprise.ui.*;
    import flash.events.*;
    import reprise.controls.*;
    import net.wooga.pets.events.*;
    import net.wooga.pets.models.*;
    import net.wooga.pets.constants.*;
    import org.robotlegs.mvcs.*;
    import net.wooga.pets.utils.*;

    public class AbstractPopupMediator extends Mediator {

        public var language:LanguageModel;
        public var sessionModel:SessionModel;
        protected var _popupType:String;
        private var _closeButton:SimpleButton;

        override public function onRegister():void{
            super.onRegister();
            addContextListener(EventConstants.CLOSE_POPUP_BY_TYPE, this.onClosePopup, InfoEvent);
            addContextListener(ProtocolConstants.POW_PUBLISH, this.onPostOnWallResult, InfoEvent);
            addContextListener(ProtocolConstants.POW_CANCEL, this.onPostOnWallResult, InfoEvent);
            addContextListener(EventConstants.UPDATE_ASK_FOR_GIFT_BUTTON, this.onUpdateAskForGiftButton, InfoEvent);
            this.addCloseButton();
        }
        private function onClosePopup(_arg1:InfoEvent):void{
            if (_arg1.id == this._popupType){
                this.onClose(null);
            };
        }
        protected function onPostOnWallResult(_arg1:InfoEvent):void{
            var _local6:String;
            var _local2 = (_arg1.type == ProtocolConstants.POW_PUBLISH);
            var _local3:Array = (_arg1.info as Array);
            var _local4:Object = _local3[0];
            var _local5:String = _local4.feed_type;
            this.handlePostOnWallResult(_local2, _local5);
            if ((((_arg1.type == ProtocolConstants.POW_PUBLISH)) && ((_local5 == GameConstants.ASK_FOR_SYMBOL)))){
                _local6 = _local4.optional_type;
                this.handleRequestLimits(_local6);
            };
        }
        protected function handlePostOnWallResult(_arg1:Boolean, _arg2:String):void{
        }
        protected function onUpdateAskForGiftButton(_arg1:InfoEvent):void{
            var _local2:String = _arg1.info.type;
            this.handleRequestLimits(_local2);
        }
        protected function handleRequestLimits(_arg1:String):void{
            this.sessionModel.setRequestLimit(_arg1, true);
            this.hideAskButton(_arg1);
        }
        protected function hideAskButton(_arg1:String):void{
        }
        protected function addOkButton(_arg1:String, _arg2:UIComponent=null):void{
            var _local3:LabelButton = this.createOkButton(_arg1, _arg2);
            eventMap.mapListener(_local3, MouseEvent.CLICK, this.onOk);
        }
        protected function createOkButton(_arg1:String, _arg2:UIComponent=null):LabelButton{
            return (this.createButton(_arg2, "rectButton", _arg1, "showcardGothicFontOutline"));
        }
        protected function createButton(_arg1:UIComponent, _arg2:String, _arg3:String, _arg4:String, _arg5:Object=null):LabelButton{
            _arg1 = ((_arg1) || (this.view));
            return (RepriseUtils.addLabelButton(_arg1, _arg2, this.language.getTextByKey(_arg3, _arg5), null, null, _arg4));
        }
        protected function addCloseButton():void{
            this._closeButton = RepriseUtils.addSimpleButton(this.view, "closeButton");
            eventMap.mapListener(this._closeButton, MouseEvent.CLICK, this.onClose);
        }
        protected function onOk(_arg1:MouseEvent):void{
            this.close();
        }
        protected function onClose(_arg1:MouseEvent):void{
            this.close();
        }
        protected function close():void{
            dispatch(new Event(EventConstants.BUBBLE_CLOSED));
            var _local1:InfoEvent = new InfoEvent(EventConstants.DESTROY_POPUP, null, this.view);
            dispatch(_local1);
        }
        protected function addLabel(_arg1:String, _arg2:String, _arg3:Object=null, _arg4:UIComponent=null, _arg5:String=null):void{
            var _local6:String = this.language.getTextByKey(_arg2, _arg3);
            RepriseUtils.addLabel(((_arg4) || (this.view)), _arg1, _local6, _arg5);
        }
        private function get view():AbstractPopupView{
            return ((viewComponent as AbstractPopupView));
        }
        protected function track(_arg1:Object):void{
            dispatch(new TrackingEvent(TrackingConst.TRACK, TrackingConst.EVENT, _arg1));
        }
        protected function get closeButton():SimpleButton{
            return (this._closeButton);
        }

    }
}//package net.wooga.pets.views.popups 
